home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
pibt3sp3.arc
/
PIBTIMER.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-09-07
|
16KB
|
322 lines
(*--------------------------------------------------------------------------*)
(* TimeOfDayH --- Get time of day in 1/100 seconds from midnight *)
(*--------------------------------------------------------------------------*)
FUNCTION TimeOfDayH : REAL;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: TimeOfDayH *)
(* *)
(* Purpose: Gets time of day from internal clock in 1/100 seconds *)
(* *)
(* Calling sequence: *)
(* *)
(* Tod := TimeOfDayH : REAL; *)
(* *)
(* Tod --- Real number which is timer value expressed in *)
(* hundredths of seconds as: *)
(* ( 360000 x hour + 6000 x minutes + 100 x seconds + *)
(* hundredths of seconds ). *)
(* *)
(* Calls: INTR *)
(* *)
(*--------------------------------------------------------------------------*)
VAR
Regs: RegPack;
BEGIN (* TimeOfDayH *)
(* Time of day interrupt *)
Regs.Ax := $2C00;
INTR( $21 , Regs );
(* Convert to hundredths of seconds *)
(* from 12AM *)
WITH Regs DO
TimeOfDayH := Ch * 360000.0 + Cl * 6000.0 + Dh * 100.0 + Dl;
END (* TimeOfDayH *);
(*--------------------------------------------------------------------------*)
(* TimeDiffH --- Get difference in time between two timer values *)
(*--------------------------------------------------------------------------*)
FUNCTION TimeDiffH( Timer1, Timer2: REAL ) : REAL;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: TimeDiffH *)
(* *)
(* Purpose: Get difference in time between two timer values *)
(* in hundredths of seconds. *)
(* *)
(* Calling sequence: *)
(* *)
(* Tdiff := TimeDiffH( Timer1, Timer2: REAL ) : REAL; *)
(* *)
(* Timer1 --- first timer value (earlier) *)
(* Timer2 --- second timer value (later) *)
(* *)
(* Tdiff --- difference between timer values *)
(* *)
(* Calls: None *)
(* *)
(* Remarks: *)
(* *)
(* This routine will handle time wrap around midnight. However, it *)
(* only handles timer values <= 24 hours in duration. *)
(* *)
(*--------------------------------------------------------------------------*)
CONST
Hundredths_Secs_Per_Day = 8640000.0 (* 1/100 Seconds in one day *);
VAR
TDiff : REAL;
BEGIN (* TimeDiffH *)
TDiff := Timer2 - Timer1;
IF Tdiff < 0.0 THEN Tdiff := Tdiff + Hundredths_Secs_Per_Day;
TimeDiffH := Tdiff;
END (* TimeDiffH *);
(*--------------------------------------------------------------------------*)
(* TimeStringH --- convert timer value in 1/100 secs to string *)
(*--------------------------------------------------------------------------*)
FUNCTION TimeStringH( Timer_Value : REAL ) : AnyStr;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: TimeStringH *)
(* *)
(* Purpose: Convert elapsed timer value to HH:MM:SS string *)
(* *)
(* Calling sequence: *)
(* *)
(* Tstring := TimeStringH( Timer_Value : REAL ) : AnyStr; *)
(* *)
(* Timer_Value --- Real number which is timer value expressed as *)
(* 1/100 seconds from 12 am. *)
(* Tstring --- Resultant 'HH:MM:SS' form of time *)
(* *)
(* Calls: None *)
(* *)
(*--------------------------------------------------------------------------*)
VAR
Hours: INTEGER;
Minutes: INTEGER;
Seconds: INTEGER;
Save_H: REAL;
SH: STRING[2];
SM: STRING[2];
SS: STRING[2];
BEGIN (* TimeStringH *)
Timer_Value := INT( Timer_Value / 100.0 );
Hours := TRUNC( Timer_Value / 3600.0 );
Save_H := Timer_Value - Hours * 3600.0;
Minutes := TRUNC( Save_H / 60.0 );
Seconds := TRUNC( Save_H - Minutes * 60.0 );
STR( Hours:2, SH );
STR( Minutes:2, SM );
STR( Seconds:2, SS );
IF SH[1] = ' ' THEN SH[1] := '0';
IF SM[1] = ' ' THEN SM[1] := '0';
IF SS[1] = ' ' THEN SS[1] := '0';
TimeStringH := SH + ':' + SM + ':' + SS;
END (* TimeStringH *);
(*--------------------------------------------------------------------------*)
(* TimeOfDay --- Get time of day *)
(*--------------------------------------------------------------------------*)
FUNCTION TimeOfDay : REAL;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: TimeOfDay *)
(* *)
(* Purpose: Gets time of day from internal clock *)
(* *)
(* Calling sequence: *)
(* *)
(* Tod := TimeOfDay : REAL; *)
(* *)
(* Tod --- Real number which is timer value expressed in *)
(* seconds as: *)
(* ( 3600 x hour + 60 x minutes + seconds ) *)
(* *)
(* Calls: INTR *)
(* *)
(*--------------------------------------------------------------------------*)
VAR
Regs: RegPack;
BEGIN (* TimeOfDay *)
(* Time of day interrupt *)
Regs.Ax := $2C00;
INTR( $21 , Regs );
(* Convert to number of seconds since *)
(* 12AM *)
WITH Regs DO
TimeOfDay := Ch * 3600.0 + Cl * 60.0 + Dh;
END (* TimeOfDay *);
(*--------------------------------------------------------------------------*)
(* TimeDiff --- Get difference in time between two timer values *)
(*--------------------------------------------------------------------------*)
FUNCTION TimeDiff( Timer1, Timer2: REAL ) : REAL;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: TimeDiff *)
(* *)
(* Purpose: Get difference in time between two timer values in *)
(* seconds. *)
(* *)
(* Calling sequence: *)
(* *)
(* Tdiff := TimeDiff( Timer1, Timer2: REAL ) : REAL; *)
(* *)
(* Timer1 --- first timer value (earlier) *)
(* Timer2 --- second timer value (later) *)
(* *)
(* Tdiff --- difference between timer values *)
(* *)
(* Calls: None *)
(* *)
(* Remarks: *)
(* *)
(* This routine will handle time wrap around midnight. However, it *)
(* only handles timer values <= 24 hours in duration. *)
(* *)
(*--------------------------------------------------------------------------*)
CONST
Secs_Per_Day = 86400.0 (* Seconds in one day *);
VAR
TDiff : REAL;
BEGIN (* TimeDiff *)
TDiff := Timer2 - Timer1;
IF Tdiff < 0.0 THEN Tdiff := Tdiff + Secs_Per_Day;
TimeDiff := Tdiff;
END (* TimeDiff *);
(*--------------------------------------------------------------------------*)
(* TimeString --- convert timer value to string *)
(*--------------------------------------------------------------------------*)
FUNCTION TimeString( Timer_Value : REAL ) : AnyStr;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: TimeString *)
(* *)
(* Purpose: Convert elapsed timer value to HH:MM:SS string *)
(* *)
(* Calling sequence: *)
(* *)
(* Tstring := TimeString( Timer_Value : REAL ) : AnyStr; *)
(* *)
(* Timer_Value --- Real number which is timer value expressed as *)
(* seconds from 12 am. *)
(* Tstring --- Resultant 'HH:MM:SS' form of time *)
(* *)
(* Calls: None *)
(* *)
(*--------------------------------------------------------------------------*)
VAR
Hours: INTEGER;
Minutes: INTEGER;
Seconds: INTEGER;
Save_H: REAL;
SH: STRING[2];
SM: STRING[2];
SS: STRING[2];
BEGIN (* TimeString *)
Hours := TRUNC( Timer_Value / 3600.0 );
Save_H := Timer_Value - Hours * 3600.0;
Minutes := TRUNC( Save_H / 60.0 );
Seconds := TRUNC( Save_H - Minutes * 60.0 );
STR( Hours:2, SH );
STR( Minutes:2, SM );
STR( Seconds:2, SS );
IF SH[1] = ' ' THEN SH[1] := '0';
IF SM[1] = ' ' THEN SM[1] := '0';
IF SS[1] = ' ' THEN SS[1] := '0';
TimeString := SH + ':' + SM + ':' + SS;
END (* TimeString *);
(*--------------------------------------------------------------------------*)
(* DateString --- Return current date in MM/DD/YY form *)
(*--------------------------------------------------------------------------*)
FUNCTION DateString: AnyStr;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: DateString *)
(* *)
(* Purpose: Returns current date in MM/DD/YY form *)
(* *)
(* Calling sequence: *)
(* *)
(* Dstring := DateString: AnyStr; *)
(* *)
(* Dstring --- Resultant 'MM/DD/YY' form of date *)
(* *)
(* Calls: MsDos *)
(* *)
(*--------------------------------------------------------------------------*)
VAR
RecPack: regpack;
Month: STRING[2];
Day: STRING[2];
Year: STRING[4];
BEGIN (* DateString *)
(* Date function *)
RecPack.Ax := $2A00;
(* Get date from DOS *)
MsDos( RecPack );
(* Convert to MM/DD/YY string *)
WITH Recpack DO
BEGIN
STR( Cx , Year );
STR( Dx MOD 256 , Day );
STR( Dx SHR 8 , Month );
END;
DateString := Month + '/' + Day + '/' + Year;
END (* DateString *);